var pasvalue = ''
const validatePass = (rule, value, callback) => {
  var pasw = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,18}$/;//6到16位数字与字母组合
  pasvalue = value
  if (pasw.test(value)) {
    callback()
  } else {
    callback(new Error('请输入6到18位数字与字母组合'))
  }
}
const validatePassa = (rule, value, callback) => {
  var pasw = /^\d{6}$/;//6到16位数字与字母组合
  pasvalue = value;
  if (pasw.test(value)) {
    callback()
  } else {
    callback(new Error('请输入6位数字密码'))
  }
}
const validatePassagin = (rule, value, callback) => {
  if (pasvalue == value) {
    callback()
  } else {
    callback(new Error('两次密码不一致'))
  }
}
const phonevailable = (rule, value, callback) => {
  var pmyreg = /^[1][3,4,5,7,8,9][0-9]{9}$/ //手机号
  if (pmyreg.test(value)) {
    callback()
  } else {
    callback(new Error('请输入正确的手机号'))
  }
}
const emailvailable = (rule, value, callback) => {
  var pattern = /^([A-Za-z0-9_\-.])+@([A-Za-z0-9_\-.])+\.([A-Za-z]{2,4})$/ //邮箱
  if (pattern.test(value)) {
    callback()
  } else {
    callback(new Error('请输入正确邮箱地址'))
  }
};
const uservailable = (rule, value, callback) => {
  var pattern = /^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/ //身份证验证
  if (pattern.test(value)) {
    callback()
  } else {
    callback(new Error('请输入正确身份证'))
  }
};

const cardvalidate = (rule, value, callback) => {
  var card = /^\d{20}$/
  if (card.test(value)) {
    callback()
  } else {
    callback(new Error('请输入正确卡号'))
  }
};

const moneyvailable = (rule, value, callback) => {
  var pattern = /\d+\.?\d{0,2}/; //注册资金
  if (pattern.test(value) && value >= 0) {
    callback()
  } else {
    callback(new Error('请输入正确的金额'))
  }
}
const rechargevailable = (rule, value, callback) => {
  var patterns = /^\d+\.?\d{0,2}$/;
  if (patterns.test(value) && value >= 1 && value <= 100000) {
    callback()
  } else if (value < 1) {
    callback(new Error('请输入正确额度,额度不得小于1元'))
  } else if (value > 100000) {
    callback(new Error('请输入正确额度,额度不得大于100000元'))
  } else if (!patterns.test(value)) {
    callback(new Error('请输入正确额度,小数点保留2位有效数字'))
  }
}

const drawUpVailable = (rule, value, callback) => {
  var patterns = /^\d+\.?\d{0,2}$/;
  if (patterns.test(value) && value >= 0 && value <= 200) {
    callback()
  } else if (value < 0) {
    callback(new Error('请输入正确金额,金额不得小于0元'))
  } else if (value > 200) {
    callback(new Error('请输入正确金额,金额不得大于200元'))
  } else if (!patterns.test(value)) {
    callback(new Error('请输入正确金额,小数点保留2位有效数字'))
  }
}

const limitvailables = (rule, value, callback) => {
  var patterns = /^\d{0,6}$/;
  if (patterns.test(value) && value >= 0 && value <= 100000) {
    callback()
  } else if (value < 0) {
    callback(new Error('请输入正确额度,额度不得为负数'))
  } else if (value > 100000) {
    callback(new Error('请输入正确额度,额度不得大于100000元'))
  } else if (!patterns.test(value)) {
    callback(new Error('请输入正确额度'))
  }
}
const versionvailables = (rule, value, callback) => {
  var version = /^\d{4}$/ //版本号验证
  if (version.test(value)) {
    callback()
  } else {
    callback(new Error('输入正确的4位数字版本号'))
  }
}

const Number = (rule, value, callback) => {
  var card = /^[0-19]*$/
  if (card.test(value)) {
    callback()
  } else {
    callback(new Error('请输入正确编号'))
  }
}

export default { Number, validatePass, phonevailable, emailvailable, moneyvailable, validatePassagin, uservailable, cardvalidate, rechargevailable, limitvailables, validatePassa, versionvailables,drawUpVailable }
